class RelativeMemoToOpenSourceProject < ActiveRecord::Base
  # attr_accessible :title, :body
  belongs_to :open_source_project, :foreign_key => "osp_id"
  belongs_to :topic, :class_name => 'RelativeMemo', :foreign_key => 'relative_memo_id'
  has_one :relative_memos, :class_name => 'RelativeMemo', :foreign_key => 'id'
  has_many :no_uses, :as => :no_use, :dependent => :delete_all
  set_primary_key "id"
  validates_presence_of :osp_id, :relative_memo_id

  scope :no_use_for, lambda { |user_id|
    {:include => :no_uses,
     :conditions => ["#{NoUse.table_name}.user_id = ?", user_id] }
  }
  
  def self.getTableName(osp_id)
    targetTableName = 'relative_memo_to_open_source_projects'
    if osp_id >= 770000 && osp_id <= 800000
      targetTableName = 'relative_memo_to_open_source_projects_70'
    elsif osp_id > 800000 && osp_id<78000000
      tmp = 71 + osp_id%20
      targetTableName = "relative_memo_to_open_source_projects_" + tmp.to_s
    else
      a = 1 + osp_id/11000
      targetTableName = 'relative_memo_to_open_source_projects_' + a.to_s
    end
    return targetTableName
  end

  #solr search
  #searchable do
  #  integer :osp_id
  #  integer :relative_memo_id
  #  float :match_weight
  #end

end
